package com.ruoyi.course.utils;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.course.enums.RoleEnum;
import com.ruoyi.system.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RoleUtils {
    @Autowired
    private ISysRoleService sysRoleService;

    /**
     * 判断当前用户是否拥有系主任身份
     * @return
     */
    public Boolean isDirector() {
        List<SysRole> roleList = sysRoleService.selectRoleByUserId(SecurityUtils.getUserId());
        for (SysRole sysRole : roleList) {
            if (RoleEnum.ROLE_DIRECTOR.getRole().equals(sysRole.getRoleKey())) {
                return true;
            }
        }
        return false;
    }

    /**
     * 判断当前用户是否拥有教师身份
     * @return
     */
    public Boolean isTeacher() {
        List<SysRole> roleList = sysRoleService.selectRoleByUserId(SecurityUtils.getUserId());
        for (SysRole sysRole : roleList) {
            if (RoleEnum.ROLE_TEACHER.getRole().equals(sysRole.getRoleKey())) {
                return true;
            }
        }
        return false;
    }

    /**
     * 判断当前用户是否拥有学生身份
     * @return
     */
    public Boolean isStudent() {
        List<SysRole> roleList = sysRoleService.selectRoleByUserId(SecurityUtils.getUserId());
        for (SysRole sysRole : roleList) {
            if (RoleEnum.ROLE_STUDENT.getRole().equals(sysRole.getRoleKey())) {
                return true;
            }
        }
        return false;
    }
}
